package com.lxk.utils;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

public class PropertiesUtils {
    private static Properties  properties = new Properties();
    private static Map<String,String> PROPER_MAP = new ConcurrentHashMap<>();

    static {
        InputStream in = null;
        try{
            in = PropertiesUtils.class.getClassLoader().getResourceAsStream("application.properties");
            properties.load(new InputStreamReader( in,"utf-8"));// 加载属性文件(指定了编码

            Iterator<Object> iterator = properties.keySet().iterator();
            while(iterator.hasNext()){
                String key = (String) iterator.next();
                PROPER_MAP.put(key,properties.getProperty(key));
            }
        }catch(Exception e){

        }finally {
            if(in != null){
                try{
                    in.close();
                }catch(Exception e){
                    e.printStackTrace();
                }
            }
        }
    }

    public static String getString(String key){
        return PROPER_MAP.get(key);
    }

//    public static void main(String[] args) {
//        System.out.println(PropertiesUtils.getString("db.driver.name"));
//    }
}
